home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Taifun
/
Taifun 054 (1988-05-15)(Ossowski, Stefan)(DE)(PD).zip
/
Taifun 054 (1988-05-15)(Ossowski, Stefan)(DE)(PD).adf
/
MRBackup
/
MRBackup2.0
/
UserPrefs.c
< prev
Wrap
C/C++ Source or Header
|
1988-04-09
|
6KB
|
285 lines
/* MRBackup user preferences processing.
* Filename: UserPrefs.c
* Date: 08/23/87
*
* History: (most recent change first)
*
* 12/20/87 -MRR- Added PutUserPrefs to allow saving new preferences.
* 11/23/87 -MRR- Version 2.0.
*
*/
#include "MRBackup.h"
char *fgets();
extern struct Gadget backPathGadget;
extern struct Gadget xcldPathGadget;
extern struct Gadget homePathGadget;
extern struct Gadget listPathGadget;
extern struct Menu Menu1;
#define KEYMAX 20 /* max length of a keyword */
#define NKEYWORD 9 /* number of keywords supported */
#define PREFERENCES_FILE "S:MRBackup.init"
#define KW_HOME 0
#define KW_BACKUP 1
#define KW_LIST 2
#define KW_EXCLUDE 3
#define KW_COMPRESSION 4
#define KW_LISTING 5
#define KW_SPEECH 6
#define KW_FORMAT 7
#define KW_BIGFILES 8
static char *keywords[NKEYWORD] = {
"home", "backup", "list", "exclude",
"compression", "listing", "speech",
"format","bigfiles"
};
/* Process the user preferences file. */
GetUserPrefs()
{
char c;
USHORT i;
char keyword[KEYMAX+1];
short keyindex;
USHORT keyleng;
FILE *prefs;
char s[81];
char *s1, *s2, *s3;
if (!(prefs = fopen(PREFERENCES_FILE,"r"))) {
WriteConsole("I couldn't get your preferences.\n");
return;
}
while (fgets(s, 80, prefs)) {
if (*s == '#') continue;
WriteConsole(s);
s1 = s;
keyleng = 0;
while ((c = *s1++) && isalpha(c)) {
if (keyleng < KEYMAX) keyword[keyleng++] = tolower(c);
else {
badkey:
WriteConsole("Keyword error in preferences file.\n");
err:
goto done;
}
}
keyword[keyleng] = '\0';
for (keyindex = -1, i = 0; i < NKEYWORD; ++i) {
if (!strcmp(keyword, keywords[i])) {
keyindex = i; /* found it */
break;
}
}
if (keyindex < 0) goto badkey;
while (c == ' ' || c == '\t') c = *s1++;
if (c != '=') {
badsyn:
WriteConsole("Syntax error in preferences file.\n");
goto done;
}
/* Get the parameter field, minus any leading or trailing
* blanks.
*/
while ((c = *s1) == ' ' || c == '\t') ++s1; /* skip leading blanks */
/* Delete trailing blanks. */
s2 = s3 = s1;
while (c && c != '\n') {
if (c != ' ' && c != '\t') s2 = s3; /* record non-blank end */
c = *s3++;
}
*s2 = '\0'; /* truncate the string here */
SetUserPref(keyindex, s1);
}
done:
fclose(prefs);
}
/* Output a boolean preference setting.
* Called with:
* f: preferences file descriptor
* value: boolean value
*/
PutBoolPref(f, value)
FILE *f; unsigned value;
{
char *s;
s = (value ? "YES" : "NO");
fputs(s, f);
}
/* Save the current program settings in the user preferences file. */
PutUserPrefs()
{
char backupName[81]; /* backup path name */
unsigned keyIndex;
FILE *prefs;
strcpy(backupName, PREFERENCES_FILE);
strcat(backupName, ".bak");
if ( CopyFile(PREFERENCES_FILE, backupName) )
TypeAndSpeak(
"I couldn't back up the current preferences but I'll go on.\n");
if (!(prefs = fopen(PREFERENCES_FILE, "w") ) ) {
sprintf(conmsg,
"I couldn't open the preferences file, %s, for output;\n error %d\n",
PREFERENCES_FILE, errno);
return;
}
for (keyIndex = 0; keyIndex < NKEYWORD; ++keyIndex) {
fprintf(prefs,"%s = \t\t", keywords[keyIndex]);
switch (keyIndex) {
case KW_HOME:
fputs(homePath,prefs);
break;
case KW_BACKUP:
fputs(backPath,prefs);
break;
case KW_LIST:
fputs(listPath,prefs);
break;
case KW_EXCLUDE:
fputs(excludePath,prefs);
break;
case KW_COMPRESSION:
PutBoolPref(prefs, doFormat);
break;
case KW_LISTING:
PutBoolPref(prefs, doListing);
break;
case KW_SPEECH:
PutBoolPref(prefs, doSpeech);
break;
case KW_FORMAT:
PutBoolPref(prefs, doFormat);
break;
case KW_BIGFILES:
PutBoolPref(prefs, doBigFiles);
break;
default:
sprintf(conmsg,
"Program error in PutUserPrefs for keyword \"%s\". Please report this.\n",
keywords[keyIndex]);
TypeAndSpeak(conmsg);
}
fputs("\n", prefs);
}
fclose(prefs);
}
/* Set/Clear checkmarks according to the item being set.
* Called with:
* thisItem: menu item number
* value: character string containing some form of YES or NO
*/
BOOL
SetMenuItem(itemNumber, value)
USHORT itemNumber; char *value;
{
BOOL boolean;
LONG menu;
struct MenuItem *item;
short i;
/* Get pointers and menu numbers for the affected items. */
menu = SHIFTITEM((long) itemNumber) | SHIFTMENU((long) MENU_FLAGS);
item = ItemAddress(&Menu1, menu);
if (item == NULL) {
WriteConsole("Null menu item in SetMenuItem - call Mark!!\n");
return false;
}
boolean = ( tolower(*value) == 'y' );
if (boolean) { /* true? */
item->Flags |= CHECKED;
}
else { /* false */
item->Flags &= ~CHECKED;
}
return boolean;
}
void
SetStringGadget(gadget, value)
struct Gadget *gadget; char *value;
{
UBYTE *gs; /* pointer to gadget string */
RemoveGadget(pathWindow, gadget);
gs = (UBYTE *) GadgetString(gadget);
strcpy(gs, value);
ResetStringInfo(gadget->SpecialInfo);
AddGadget(pathWindow, gadget, -1L);
DoGadget(pathWindow, GADGETUP, gadget); /* simulate GADGETUP */
}
/* Set one user preference item.
* Called with:
* kw: keyword index
* parm: parameter string
*/
SetUserPref(kw, parm)
USHORT kw; char *parm;
{
switch (kw) {
case KW_HOME:
SetStringGadget(&homePathGadget, parm);
break;
case KW_BACKUP:
SetStringGadget(&backPathGadget, parm);
break;
case KW_LIST:
SetStringGadget(&listPathGadget, parm);
break;
case KW_LISTING:
doListing = SetMenuItem(ITEM_LIST, parm);
break;
case KW_EXCLUDE:
SetStringGadget(&xcldPathGadget, parm);
break;
case KW_COMPRESSION:
doCompress = SetMenuItem(ITEM_COMPRESS, parm);
break;
case KW_SPEECH:
doSpeech = SetMenuItem(ITEM_SPEECH, parm);
break;
case KW_FORMAT:
doFormat = SetMenuItem(ITEM_FORMAT, parm);
break;
case KW_BIGFILES:
doBigFiles = SetMenuItem(ITEM_BIGFILES, parm);
break;
default:
break;
}
}